import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CustomerCategoryVO, CustomerCategoryForm, CustomerCategoryQuery } from '@/api/finance/customerCategory/types';

/**
 * 查询客户分类列表
 * @param query
 * @returns {*}
 */

export const listCustomerCategory = (query?: CustomerCategoryQuery): AxiosPromise<CustomerCategoryVO[]> => {
  return request({
    url: '/finance/customerCategory/list',
    method: 'get',
    params: query
  });
};
//查询末级客户分类列表
export const listLeafCategory = (query?: CustomerCategoryQuery): AxiosPromise<CustomerCategoryVO[]> => {
  return request({
    url: '/finance/customerCategory/listIgnoreParent',
    method: 'get',
    params: query
  });
};

/**
 * 查询客户分类详细
 * @param id
 */
export const getCustomerCategory = (id: string | number): AxiosPromise<CustomerCategoryVO> => {
  return request({
    url: '/finance/customerCategory/' + id,
    method: 'get'
  });
};

/**
 * 新增客户分类
 * @param data
 */
export const addCustomerCategory = (data: CustomerCategoryForm) => {
  return request({
    url: '/finance/customerCategory',
    method: 'post',
    data: data
  });
};

/**
 * 修改客户分类
 * @param data
 */
export const updateCustomerCategory = (data: CustomerCategoryForm) => {
  return request({
    url: '/finance/customerCategory',
    method: 'put',
    data: data
  });
};

/**
 * 删除客户分类
 * @param id
 */
export const delCustomerCategory = (id: string | number | Array<string | number>) => {
  return request({
    url: '/finance/customerCategory/' + id,
    method: 'delete'
  });
};
